<template>
  <view class="" style="background: #e9ecf1">
    <view
      style="
        width: 730rpx;
        background-color: #fff;
        margin: 0 auto;
        margin-top: 20rpx;
      "
    >
      <!-- <jp-signature ref="signatureRef"></jp-signature> -->
      <jushi-signature
        :settings="settings"
        @change="signatureChange"
      ></jushi-signature>
    </view>
    <!-- <view class="setazs">
			<view class="quexiao" @click="clear">
				取消
			</view>
			<view class="qeuren" @click="save">
				确认
			</view>

		</view> -->
    <view class="" style="height: 20rpx"> </view>
  </view>
</template>

<script>
import { websock } from "../../net/websock";
import store from "../../store";
import { uploadconfig2, uploadconfig } from "../../const";
export default {
  // props:{
  // 	title
  // }
  data() {
    return {
      title: "",
      url: "",
      settings: {
        //签名设置
        width: "750", //签名区域的宽
        height: "500", //签名区域的高
        lineWidth: 3, //签名时线宽
        textColor: "#575757", //签名文字颜色
      },
      userInfo: {},
    };
  },
  onLoad(options) {
    console.log(options);
    this.title = options.UrlName;
  },
  async onReady() {
    this.userInfo = await websock.getUserInfo();
  },
  methods: {
    jumperBack() {
      this.$emit("jumperBack");
      // uni.switchTab({
      // 	url: '/pages/workbench/index'
      // })
    },
    async signatureChange(e) {
      console.log(e)
      let that = this;
			console.log(uploadconfig2.url);
      uni.uploadFile({
        url: uploadconfig.urlModifySign,
        filePath: e,
				name: 'file',
        formData: { 
          uid: this.userInfo.uid,
          token: store.token
        },
        success: async res => {
          try {
            let data = JSON.parse(res.data)
            if (data.code != 0) {
              return uni.showToast({ title: data.message })
            }
            store.userInfo = null
            this.userInfo = await websock.getUserInfo()
            uni.navigateTo({
              url: '/pages/my/modifySign'
            });
          } catch (e) {
            console.error(e)
            uni.showToast({
              title: '修改签名失败1' + e.message
            })
          }
          console.log('success', res)
        },
        fail: (res) => {
          uni.showToast({ title: '修改签名失败2' + res })
        },
        complete: () => {
          console.log('modify avatar complete')
        }
      })
    },
    save() {
      let that = this;
      this.$refs.signatureRef.canvasToTempFilePath({
        success: (res) => {
          // 是否为空画板 无签名
          console.log(res);
          // 生成图片的临时路径
          // H5 生成的是base64
          console.log(res, " res.tempFilePath");
        },
      });
    },
    clear() {
      this.$refs.signatureRef.clear();
    },
    undo() {
      this.$refs.signatureRef.undo();
    },
  },
};
</script>

<style lang="scss" scoped>
.setazs {
  display: flex;
  padding: 10rpx;
  margin-top: 20rpx;
  background-color: #fff;
  justify-content: space-around;
}

.talentPool_flex_0 {
  top: 0rpx;
  z-index: 100;
  width: 750rpx;
  height: 80rpx;
  line-height: 80rpx;
  display: flex;
  background-color: #3b95ff;
  justify-content: space-around;
  background-size: 100% !important;
  background-size: 100% auto !important;

  .talentPool_fd0_0_c1_c0 {
    height: 48rpx;
    text-align: center;
    font-size: 36rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: bold;
    color: #ffffff;
    line-height: 42rpx;
  }

  .icon-fanhui {
    color: #ffffff;
  }

  .bodX {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .iconFont {
    margin-left: 20rpx;
    margin-right: -40rpx;
  }
}
</style>
